/**
 * Created by user on 2017/9/22.
 */
import store from 'store';
const DEFAULT_EXPIRE = NaN;
const Storage = {
    name: 'version_manager_',
    getKey:function(key){
        const name = this.name+key;
        return name;
    },
    read: function(key) {
        const tmp = store.get(this.getKey(key));
        if(!tmp) return undefined;
        const diff = new Date().getTime() - tmp.timestamp;
        if(diff > tmp.expire*1000) return undefined;
        return tmp.content;
    },
    write: function(key, value, expire) {
        const tmp = {
            timestamp:new Date().getTime(),
            content:value,
            expire: expire ? expire : DEFAULT_EXPIRE
        };
        store.set(this.getKey(key),tmp);
    },
    remove: function(key) {
        store.remove(this.getKey(key));
    },
    clearAll: function() {
        store.clearAll()
    }
};
export default Storage;